﻿Public Class TrataTif


    Public Shared Function ConvertirAMultiTiff(ByVal imagenes As List(Of Byte())) As Byte()

        Dim ms As System.IO.MemoryStream

        Dim tifDoc As New Adhoc.EDN.Tiff.TIFFDocument
        Dim tifDocIni As Adhoc.EDN.Tiff.TIFFDocument

        Dim tifR As Adhoc.EDN.Tiff.TIFFReader

        For Each img As Byte() In imagenes

            ms = New IO.MemoryStream(img)
            tifR = New Adhoc.EDN.Tiff.TIFFReader(ms)
            tifDocIni = tifR.Read(False)
            For Each tp As Adhoc.EDN.Tiff.TIFFPage In tifDocIni.Pages
                tifDoc.AddPage(tp)
            Next
            ms.Close()
            ms.Dispose()

        Next

        'Guarda la imagen en disco
        Dim ms2 As New IO.MemoryStream()
        'pathMultiTIF, IO.FileMode.Create)
        Dim tifW As New Adhoc.EDN.Tiff.TIFFWriter(tifDoc)
        tifW.SalvaTIFF(ms2)
        ConvertirAMultiTiff = ms2.ToArray
        ms2.Close()
        ms2.Dispose()


    End Function

End Class
